package Task3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerSocketEnd {
    public static void main(String[] args) {
        //1. 创建ServerSocket类型的对象并提供端口号
        ServerSocket ss = null;
        Socket accept = null;

        try {
            ss = new ServerSocket(8888);
            //2. 等待客户端的连接请求，调用accept方法

            while(true) {
                System.out.println("等待客户端的请求..");
                accept = ss.accept();
                System.out.println("客户端" + accept.getInetAddress()+"连接成功！");
                //当有一个客户端连接成功 就启动一个新的线程为之服务
                new MultiThread(accept).start();
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(ss != null){
                try {
                    ss.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }


    }


}
